package com.sptpc.demo1.service.imp;

import com.sptpc.demo1.model.Book;
import com.sptpc.demo1.repository.BookRepository;
import com.sptpc.demo1.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookJpaService implements IBookService {
    @Autowired
    BookRepository bookRepository;

    @Override
    public List<Book> getAllDrinks() {
        return bookRepository.findAll();
    }

    @Override
    public void addNewDrink(Book book) {
        bookRepository.save(book);
    }

    @Override
    public void delBook(Integer id) {
        bookRepository.deleteById(id);
    }

    @Override
    public Book getbookById(Integer id) {
        return bookRepository.findById(id).orElse(null);
    }

    @Override
    public void updateBook(Book book) {
        bookRepository.save(book);
    }
}
